package
{	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import mapEditor.MapEditor;
	import mapEditor.common.DialogBoxManager;
	
	import spark.components.Window;
	
	[SWF(width = "1000",height = "600",frameRate = "25")]
	public class Main extends Sprite
	{
		private var _toolPanelView:ToolPanelView;
		private var _mapEditor:MapEditor;
		public function Main()
		{
			stage.nativeWindow.visible = true;
			stage.nativeWindow.title="游戏编辑";
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			DialogBoxManager.Instance.register(stage);
			
			setView();
			setEvent();
		}
		
		private function setView():void
		{
			_toolPanelView=new ToolPanelView();
			
			_mapEditor=new MapEditor(stage);
			_mapEditor.y=_toolPanelView.height;
			addChild(_mapEditor);
			
			addChild(_toolPanelView);
		}
		
		private function setEvent():void
		{
			_toolPanelView.btnMap.addEventListener(MouseEvent.CLICK, __onClick);
			_toolPanelView.btnRole.addEventListener(MouseEvent.CLICK, __onClick);
		}
		
		private function __onClick(evt:MouseEvent):void
		{
			resetModule();
			switch(evt.currentTarget)
			{
				case _toolPanelView.btnMap://地图编辑器
					stage.nativeWindow.title="地图编辑";
					if(!_mapEditor)
					{
						_mapEditor=new MapEditor(stage);
						_mapEditor.y=_toolPanelView.height;
					}
					addChild(_mapEditor);
					break;
				case _toolPanelView.btnRole://角色编辑器
					stage.nativeWindow.title="角色编辑";
					break;
			}
		}
		
		private function resetModule():void
		{
			if(_mapEditor && _mapEditor.parent) _mapEditor.parent.removeChild(_mapEditor);
		}
	}
}